package me.abel.auditing.service.impl;

import me.abel.auditing.entity.DemoEntity;
import me.abel.auditing.repositories.DemoRepository;
import me.abel.auditing.service.DemoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DemoServiceImpl implements DemoService {

    private final DemoRepository demoRepository;

    public DemoServiceImpl(DemoRepository demoRepository) {
        this.demoRepository = demoRepository;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update() {
        DemoEntity entity = new DemoEntity();
        entity.setCode("111");
        entity.setName("111");
        demoRepository.saveAndFlush(entity);

        DemoEntity demoEntity = demoRepository.getById(entity.getId());
        demoEntity.setName("222");
        demoRepository.save(demoEntity);
    }
}
